<template>
  <div ref="pieRef" style="width: 100%; height: 85%"></div>
</template>
    
    <script>
import * as echarts from "echarts";
import { mapState } from "vuex";
import { getThemeValue } from "@/utils/theme_color.js";
export default {
  data() {
    return {
      chartInstance: null,
      option: {
        tooltip: {
          trigger: "axis",
          axisPointer: {
            crossStyle: {
              color: "#999",
            },
          },
        },

        grid: {
          top: "15%",
          bottom: "15%",
          left: "5%",
          right: "5%",
          containLabel: true,
        },
        legend: {
          bottom: "0%",
          icon: "circle",
          textStyle: {
            color: "rgba(255,255,255,0.8)",
          },
          itemWidth:10
        },
        xAxis: {
          type: "category",
          data: ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"],
          axisPointer: {
            type: "shadow",
          },
          axisTick: {
            show: false,
          },
          axisLabel: {
            show: true,
            color: "rgba(255,255,255,0.5)",
          },
        },

        yAxis: {
          type: "value",
          splitLine: {
            lineStyle: {
              color: "#1a1f6d",
              width: 1,
            },
          },
          axisLabel: {
            show: true,
            color: "rgba(255,255,255,0.5)",
          },
        },

        series: [
          {
            name: "Evaporation",
            type: "bar",
            data: [
              2.0, 4.9, 7.0, 23.2, 25.6, 76.7, 135.6, 162.2, 32.6, 20.0, 6.4,
              3.3,
            ],
          },
          {
            name: "Precipitation",
            type: "bar",

            data: [
              2.6, 5.9, 9.0, 26.4, 28.7, 70.7, 175.6, 182.2, 48.7, 18.8, 6.0,
              2.3,
            ],
          },
        ],
      },
    };
  },
  computed: {
    ...mapState({
      // sideTheme: (state) => state.settings.sideTheme,
    }),
  },
  methods: {
    initChart() {
      // 初始化对象
      this.chartInstance = echarts.init(this.$refs.pieRef);
      this.chartInstance.setOption(this.option, true);
      window.addEventListener("resize", () => {
        this.chartInstance.resize();
      });
    },
    getData(params) {
      let xAxis = [];
      let series = [];
      let rectified = [];
      let violationAlarm = [];
      params.forEach((item) => {
        rectified.push(item.rectifiedNum ||0)
        violationAlarm.push(item.violationAlarm||0);
        xAxis.push(item.orgName );
      });
      series = [
        {
          name: "违规",
          type: "bar",
          data: violationAlarm,
          barWidth:20
        },
        {
          name: "整改",
          type: "bar",
          data: rectified,
          barWidth:20
        },
      ];
      this.option.xAxis.data = xAxis;
      this.option.series = series;
      this.chartInstance.setOption(this.option, true);
    },
    updateChart() {
      const titleThemeDark = getThemeValue("titleThemeDark");
      const DarkThemeStyle = {
        title: {
          textStyle: {
            color: titleThemeDark.titleColor,
          },
        },
        legend: {
          textStyle: {
            color: titleThemeDark.titleColor,
          },
        },
        xAxis: {
          axisLabel: {
            color: "#617898",
          },
          axisLine: {
            show: false,
          },
        },
        yAxis: {
          axisLabel: {
            color: "#617898",
          },
          splitLine: {
            lineStyle: {
              color: "rgba(255,255,255,0.15)",
            },
          },
          axisLine: {
            show: false,
          },
        },
      };
      const titleThemeHigh = getThemeValue("titleThemeHigh");
      const HighThemeStyle = {
        title: {
          textStyle: {
            color: titleThemeHigh.titleColor,
          },
        },
        legend: {
          textStyle: {
            color: titleThemeHigh.titleColor,
          },
        },
        xAxis: {
          axisLabel: {
            color: "rgba(0,0,0,0.45)",
          },
          axisLine: {
            show: false,
          },
        },
        yAxis: {
          axisLabel: {
            color: " rgba(0,0,0,0.45)",
          },
          axisLine: {
            show: false,
          },
        },
      };
      // if (this.sideTheme == "theme-dark") {
      //   this.chart.setOption(DarkThemeStyle);
      // } else {
      //   this.chart.setOption(HighThemeStyle);
      // }
    },
  },
  mounted() {
    this.initChart();

    // 添加随页面变化而变化
    window.addEventListener("resize", () => {
      this.chartInstance.resize();
    });
  },
  destroyed() {
    window.removeEventListener("resize", () => {
      this.chartInstance.resize();
    });
  },
  watch: {
    // sideTheme: {
    //   handler(newValue) {
    //     this.updateChart();
    //   },
    // },
  },
};
</script>
    
    <style lang="scss" scoped>
.visit-app {
  width: 100%;
  height: 100%;
}
</style>
    